﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Forbidden_Island
{
    class Game
    {
        private List<Tile> tileList;
        private List<AdventureDeck> AdvDeckList;
        private List<PlaceCard> placeCardDeck;
        //private List<PlaceCard> placeCardDiscard;
        private List<PlayerClass> currentplayers;
        private List<PlayerClass> playersneededtoplay = new List<PlayerClass>();
        private int[,] validMoves = new int[24,4];
        private int[,] explorerValidDiagMoves = new int[24, 4];

        public Game()
        {
            //create tile list and decks - each is shuffled on creation, no need to do so here or in Form1
            this.tileList = createTileList();
            this.AdvDeckList = createAdvDeck();
            this.placeCardDeck = createPlaceCardDeck();
            //set list of players
        }
        public List<Tile> getTileList
        {
            get {return this.tileList; }
        }
        public List<AdventureDeck> getAdventureDeck
        {
            get { return this.AdvDeckList; }
        }
        public List<PlaceCard> getPlaceCardDeck
        {
            get { return this.placeCardDeck; }
        }

        //creates a list of current players, sets color, names an empty array for cards
        public void createplayers()
        {
            currentplayers = null;
            //create players 1-4
            Image player1Image = Image.FromFile(Environment.CurrentDirectory + "\\red token.png");
            Image player1Translucent = Image.FromFile(Environment.CurrentDirectory + "\\red token translucent.png");
            PlayerClass player1 = new PlayerClass("Engineer", 1, Color.Red, 1, player1Image, player1Translucent, 
                "Can shore up to two adjacent tiles for one action.");
            playersneededtoplay.Add(player1);
            Image player2Image = Image.FromFile(Environment.CurrentDirectory + "\\yellow token.png");
            Image player2Translucent = Image.FromFile(Environment.CurrentDirectory + "\\yellow token translucent.png");
            PlayerClass player2 = new PlayerClass("Navigator", 1, Color.Yellow, 2, player2Image, player2Translucent,
                "Can move another player up to 2 tiles for 1 action.");
            playersneededtoplay.Add(player2);
            Image player3Image = Image.FromFile(Environment.CurrentDirectory + "\\blue token.png");
            Image player3Translucent = Image.FromFile(Environment.CurrentDirectory + "\\blue token translucent.png");
            PlayerClass player3 = new PlayerClass("Pilot", 1, Color.Blue, 3, player3Image, player3Translucent,
                "Once per turn, can fly to any tile on the island for one action.");
            playersneededtoplay.Add(player3);
            Image player4Image = Image.FromFile(Environment.CurrentDirectory + "\\green token.png");
            Image player4Translucent = Image.FromFile(Environment.CurrentDirectory + "\\green token translucent.png");
            PlayerClass player4 = new PlayerClass("Explorer", 1, Color.Green, 4, player4Image, player4Translucent,
                "May move and/or shore up diagonally.");
            playersneededtoplay.Add(player4);
        }

        public List<PlayerClass> playersList
        {
            get { return this.playersneededtoplay; }
            set { this.playersneededtoplay = playersList; }
        }
        public int[,] ValidMoves
        {
            get { return this.validMoves; }
        }
        public int[,] ExplorerValidMoves
        {
            get { return this.explorerValidDiagMoves; }
        }

        public List<AdventureDeck> createAdvDeck()
        {
            //here is one hell of an adventure deck
            List<AdventureDeck> fulladvdeck = new List<AdventureDeck>();
            //create treasure cards
            AdventureDeck card1 = new AdventureDeck("Water Chalice", "Treasure", true, false, false, false, 6, 
                "Collect four Water Chalice cards and bring them to Sea King's Palace or Serpent Palace to collect the Water Chalice treasure.",
                Color.DarkGreen, Color.DarkGoldenrod);
            AdventureDeck card2 = new AdventureDeck("Earth Statue", "Treasure", true, false, false, false, 6, 
                "Collect four Earth Statue cards and bring them to the Temple of Ra or the Temple of Luna to collect the Earth Statue treasure.",
                Color.Black, Color.DarkGoldenrod);
            AdventureDeck card3 = new AdventureDeck("Fire Totem", "Treasure", true, false, false, false, 6, 
                "Collect four Fire Totem cards and bring them to the Cultist's Cave or the Reptile's Cave to collect the Fire Totem treasure.",
                Color.Firebrick, Color.DarkGoldenrod);
            AdventureDeck card4 = new AdventureDeck("Wind Carving", "Treasure", true, false, false, false, 6, 
                "Collect four Wind Carving cards and bring them to the Garden of Disquiet or the Garden of Lupus to collect the Wind Carving treasure.",
                Color.DarkMagenta, Color.DarkGoldenrod);
            for (int i = 0; i < card1.NumberinDeck; ++i)
            {
                fulladvdeck.Add(card1);
                fulladvdeck.Add(card2);
                fulladvdeck.Add(card3);
                fulladvdeck.Add(card4);
            }
            //create watersrise cards
            AdventureDeck card5 = new AdventureDeck("Waters Rise!", "Effect", false, true, false, false, 3, "Causes flood level to increase.", Color.Black, Color.DarkBlue);
            for (int i = 0; i < card5.NumberinDeck; ++i)
            {
                fulladvdeck.Add(card5);
            }
            //create sandbag cards
            AdventureDeck card6 = new AdventureDeck("SandBags", "Resource", false, false, true, false, 3,
                "Use the sandbags to shore up any tile on the island.", Color.Yellow, Color.Brown);        
            for (int i = 0; i < card6.NumberinDeck; ++i)
            {
                fulladvdeck.Add(card6);
            }
            //create helocopter cards
            AdventureDeck card7 = new AdventureDeck("Helicopter Lift", "Resource", false, false, false, true, 4, 
                "The helicopter lift can take any number of players on the same tile to any other tile on the island.",
                Color.Yellow, Color.Brown);
            for (int i = 0; i < card7.NumberinDeck; ++i)
            {
                fulladvdeck.Add(card7);
            }
            fulladvdeck.ShuffleInPlace();
            return fulladvdeck;
        }

        //new game - create place card deck
        public List<PlaceCard> createPlaceCardDeck()
        {
            List<PlaceCard> placeCardList = new List<PlaceCard>();
            //create all artifact place tiles
            PlaceCard earthTemple1 = new PlaceCard("Temple of Luna", Color.Black, Color.Gold, Color.Black, true);
            PlaceCard earthTemple2 = new PlaceCard("Temple of Ra", Color.Black, Color.Gold, Color.Black, true);
            PlaceCard airTemple1 = new PlaceCard("Garden of Lupus", Color.DarkMagenta, Color.Gold, Color.DarkMagenta, true);
            PlaceCard airTemple2 = new PlaceCard("Garden of Disquiet", Color.DarkMagenta, Color.Gold, Color.DarkMagenta, true);
            PlaceCard fireTemple1 = new PlaceCard("Cultist's Cave", Color.Red, Color.Gold, Color.Red, true);
            PlaceCard fireTemple2 = new PlaceCard("Reptile's Cave", Color.Red, Color.Gold, Color.Red, true);
            PlaceCard waterTemple1 = new PlaceCard("Serpent Palace", Color.MediumSeaGreen, Color.Gold, Color.MediumSeaGreen, true);
            PlaceCard waterTemple2 = new PlaceCard("Sea King's Palace", Color.MediumSeaGreen, Color.Gold, Color.MediumSeaGreen, true);
            //add all artifact temples to list
            placeCardList.Add(earthTemple1);
            placeCardList.Add(earthTemple2);
            placeCardList.Add(airTemple1);
            placeCardList.Add(airTemple2);
            placeCardList.Add(fireTemple1);
            placeCardList.Add(fireTemple2);
            placeCardList.Add(waterTemple1);
            placeCardList.Add(waterTemple2);
            //create Freedom Landing
            PlaceCard freedomLanding = new PlaceCard("Freedom's Landing", Color.Blue, Color.LightCoral, Color.Blue, true);
            //add Freedom Landing to list
            placeCardList.Add(freedomLanding);
            //create generic place tiles
            PlaceCard theQuaq = new PlaceCard("The Quagmire", Color.Black, Color.Silver, Color.DimGray, false);
            PlaceCard winHollow = new PlaceCard("Windy Hollow", Color.Black, Color.Silver, Color.DimGray, false);
            PlaceCard corGate = new PlaceCard("Corroded Gate", Color.Black, Color.Silver, Color.DimGray, false);
            PlaceCard knGate = new PlaceCard("Knight's Gate", Color.Black, Color.Silver, Color.DimGray, false);
            PlaceCard skRock = new PlaceCard("Skull Rock", Color.Black, Color.Silver, Color.DimGray, false);
            PlaceCard anRuin = new PlaceCard("Ancient Ruin", Color.Black, Color.Silver, Color.DimGray, false);
            PlaceCard gloomWood = new PlaceCard("Gloomwood", Color.Black, Color.Silver, Color.DimGray, false);
            PlaceCard tarnGate = new PlaceCard("Tarnished Gate", Color.Black, Color.Silver, Color.DimGray, false);
            PlaceCard endBridge = new PlaceCard("Endless Bridge", Color.Black, Color.Silver, Color.DimGray, false);
            PlaceCard rockyEgress = new PlaceCard("Rocky Egress", Color.Black, Color.Silver, Color.DimGray, false);
            PlaceCard mystTower = new PlaceCard("Mysterious Tower", Color.Black, Color.Silver, Color.DimGray, false);
            PlaceCard widPeak = new PlaceCard("Widow's Peak", Color.Black, Color.Silver, Color.DimGray, false);
            PlaceCard witHut = new PlaceCard("Witch's Hut", Color.Black, Color.Silver, Color.DimGray, false);
            PlaceCard islOasis = new PlaceCard("Island Oasis", Color.Black, Color.Silver, Color.DimGray, false);
            PlaceCard sqGate = new PlaceCard("Squire's Gate", Color.Black, Color.Silver, Color.DimGray, false);
            //add generic tiles to the list
            placeCardList.Add(theQuaq);
            placeCardList.Add(winHollow);
            placeCardList.Add(corGate);
            placeCardList.Add(knGate);
            placeCardList.Add(skRock);
            placeCardList.Add(anRuin);
            placeCardList.Add(gloomWood);
            placeCardList.Add(tarnGate);
            placeCardList.Add(endBridge);
            placeCardList.Add(rockyEgress);
            placeCardList.Add(mystTower);
            placeCardList.Add(widPeak);
            placeCardList.Add(witHut);
            placeCardList.Add(islOasis);
            placeCardList.Add(sqGate);
            placeCardList.ShuffleInPlace();
            return placeCardList;
        }

        public List<Tile> createTileList()
        {
            List<Tile> filledList = new List<Tile>();
            //create all artifact claim tiles
            Tile earthTemple1 = new Tile("Temple of Luna", Color.Black, Color.Gold, Color.Black, true);
            Tile earthTemple2 = new Tile("Temple of Ra", Color.Black, Color.Gold, Color.Black, true);
            Tile airTemple1 = new Tile("Garden of Lupus", Color.DarkMagenta, Color.Gold, Color.DarkMagenta, true);
            Tile airTemple2 = new Tile("Garden of Disquiet", Color.DarkMagenta, Color.Gold, Color.DarkMagenta, true);
            Tile fireTemple1 = new Tile("Cultist's Cave", Color.Red, Color.Gold, Color.Red, true);
            Tile fireTemple2 = new Tile("Reptile's Cave", Color.Red, Color.Gold, Color.Red, true);
            Tile waterTemple1 = new Tile("Serpent Palace", Color.MediumSeaGreen, Color.Gold, Color.MediumSeaGreen, true);
            Tile waterTemple2 = new Tile("Sea King's Palace", Color.MediumSeaGreen, Color.Gold, Color.MediumSeaGreen, true);
            //add all artifact temples to list
            filledList.Add(earthTemple1);
            filledList.Add(earthTemple2);
            filledList.Add(airTemple1);
            filledList.Add(airTemple2);
            filledList.Add(fireTemple1);
            filledList.Add(fireTemple2);
            filledList.Add(waterTemple1);
            filledList.Add(waterTemple2);
            //create Freedom Landing
            Tile freedomLanding = new Tile("Freedom's Landing", Color.Blue, Color.LightCoral, Color.Blue, true);
            //add Freedom Landing to list
            filledList.Add(freedomLanding);
            //create generic place tiles
            Tile theQuaq = new Tile("The Quagmire", Color.Black, Color.Silver, Color.DimGray, false);
            Tile winHollow = new Tile("Windy Hollow", Color.Black, Color.Silver, Color.DimGray, false);
            Tile corGate = new Tile("Corroded Gate", Color.Black, Color.Silver, Color.DimGray, false);
            Tile knGate = new Tile("Knight's Gate", Color.Black, Color.Silver, Color.DimGray, false);
            Tile skRock = new Tile("Skull Rock", Color.Black, Color.Silver, Color.DimGray, false);
            Tile anRuin = new Tile("Ancient Ruin", Color.Black, Color.Silver, Color.DimGray, false);
            Tile gloomWood = new Tile("Gloomwood", Color.Black, Color.Silver, Color.DimGray, false);
            Tile tarnGate = new Tile("Tarnished Gate", Color.Black, Color.Silver, Color.DimGray, false);
            Tile endBridge = new Tile("Endless Bridge", Color.Black, Color.Silver, Color.DimGray, false);
            Tile rockyEgress = new Tile("Rocky Egress", Color.Black, Color.Silver, Color.DimGray, false);
            Tile mystTower = new Tile("Mysterious Tower", Color.Black, Color.Silver, Color.DimGray, false);
            Tile widPeak = new Tile("Widow's Peak", Color.Black, Color.Silver, Color.DimGray, false);
            Tile witHut = new Tile("Witch's Hut", Color.Black, Color.Silver, Color.DimGray, false);
            Tile islOasis = new Tile("Island Oasis", Color.Black, Color.Silver, Color.DimGray, false);
            Tile sqGate = new Tile("Squire's Gate", Color.Black, Color.Silver, Color.DimGray, false);
            //add generic tiles to the list
            filledList.Add(theQuaq);
            filledList.Add(winHollow);
            filledList.Add(corGate);
            filledList.Add(knGate);
            filledList.Add(skRock);
            filledList.Add(anRuin);
            filledList.Add(gloomWood);
            filledList.Add(tarnGate);
            filledList.Add(endBridge);
            filledList.Add(rockyEgress);
            filledList.Add(mystTower);
            filledList.Add(widPeak);
            filledList.Add(witHut);
            filledList.Add(islOasis);
            filledList.Add(sqGate);
            filledList.ShuffleInPlace();
            return filledList;
        }

        public void ShuffleTileList()
        {
            tileList.ShuffleInPlace();
        }
        //create valid moves array
        public void fillValidMoves()
        {
            validMoves[0, 0] = -1;
            validMoves[0, 1] = 3;
            validMoves[0, 2] = -1;
            validMoves[0, 3] = 1;
            validMoves[1, 0] = -1;
            validMoves[1, 1] = 4;
            validMoves[1, 2] = 0;
            validMoves[1, 3] = -1;
            validMoves[2, 0] = -1;
            validMoves[2, 1] = 7;
            validMoves[2, 2] = -1;
            validMoves[2, 3] = 3;
            validMoves[3, 0] = 0;
            validMoves[3, 1] = 8;
            validMoves[3, 2] = 2;
            validMoves[3, 3] = 4;
            validMoves[4, 0] = 1;
            validMoves[4, 1] = 9;
            validMoves[4, 2] = 3;
            validMoves[4, 3] = 5;
            validMoves[5, 0] = -1;
            validMoves[5, 1] = 10;
            validMoves[5, 2] = 4;
            validMoves[5, 3] = -1;
            validMoves[6, 0] = -1;
            validMoves[6, 1] = 12;
            validMoves[6, 2] = -1;
            validMoves[6, 3] = 7;
            validMoves[7, 0] = 2;
            validMoves[7, 1] = 13;
            validMoves[7, 2] = 6;
            validMoves[7, 3] = 8;
            validMoves[8, 0] = 3;
            validMoves[8, 1] = 14;
            validMoves[8, 2] = 7;
            validMoves[8, 3] = 9;
            validMoves[9, 0] = 4;
            validMoves[9, 1] = 15;
            validMoves[9, 2] = 8;
            validMoves[9, 3] = 10;
            validMoves[10, 0] = 5;
            validMoves[10, 1] = 16;
            validMoves[10, 2] = 9;
            validMoves[10, 3] = 11;
            validMoves[11, 0] = -1;
            validMoves[11, 1] = 17;
            validMoves[11, 2] = 10;
            validMoves[11, 3] = -1;
            validMoves[12, 0] = 6;
            validMoves[12, 1] = -1;
            validMoves[12, 2] = -1;
            validMoves[12, 3] = 13;
            validMoves[13, 0] = 7;
            validMoves[13, 1] = 18;
            validMoves[13, 2] = 12;
            validMoves[13, 3] = 14;
            validMoves[14, 0] = 8;
            validMoves[14, 1] = 19;
            validMoves[14, 2] = 13;
            validMoves[14, 3] = 15;
            validMoves[15, 0] = 9;
            validMoves[15, 1] = 20;
            validMoves[15, 2] = 14;
            validMoves[15, 3] = 16;
            validMoves[16, 0] = 10;
            validMoves[16, 1] = 21;
            validMoves[16, 2] = 15;
            validMoves[16, 3] = 17;
            validMoves[17, 0] = 11;
            validMoves[17, 1] = -1;
            validMoves[17, 2] = 16;
            validMoves[17, 3] = -1;
            validMoves[18, 0] = 13;
            validMoves[18, 1] = -1;
            validMoves[18, 2] = -1;
            validMoves[18, 3] = 19;
            validMoves[19, 0] = 14;
            validMoves[19, 1] = 22;
            validMoves[19, 2] = 18;
            validMoves[19, 3] = 20;
            validMoves[20, 0] = 15;
            validMoves[20, 1] = 23;
            validMoves[20, 2] = 19;
            validMoves[20, 3] = 21;
            validMoves[21, 0] = 16;
            validMoves[21, 1] = -1;
            validMoves[21, 2] = 20;
            validMoves[21, 3] = -1;
            validMoves[22, 0] = 19;
            validMoves[22, 1] = -1;
            validMoves[22, 2] = -1;
            validMoves[22, 3] = 23;
            validMoves[23, 0] = 20;
            validMoves[23, 1] = -1;
            validMoves[23, 2] = 22;
            validMoves[23, 3] = -1;
        }
        public void fillExplorerMoves()
        {
            explorerValidDiagMoves[0, 0] = -1;
            explorerValidDiagMoves[0, 1] = -1;
            explorerValidDiagMoves[0, 2] = 2;
            explorerValidDiagMoves[0, 3] = 4;
            explorerValidDiagMoves[1, 0] = -1;
            explorerValidDiagMoves[1, 1] = -1;
            explorerValidDiagMoves[1, 2] = 3;
            explorerValidDiagMoves[1, 3] = 5;
            explorerValidDiagMoves[2, 0] = -1;
            explorerValidDiagMoves[2, 1] = 0;
            explorerValidDiagMoves[2, 2] = 6;
            explorerValidDiagMoves[2, 3] = 8;
            explorerValidDiagMoves[3, 0] = -1;
            explorerValidDiagMoves[3, 1] = 1;
            explorerValidDiagMoves[3, 2] = 7;
            explorerValidDiagMoves[3, 3] = 9;
            explorerValidDiagMoves[4, 0] = 0;
            explorerValidDiagMoves[4, 1] = -1;
            explorerValidDiagMoves[4, 2] = 8;
            explorerValidDiagMoves[4, 3] = 10;
            explorerValidDiagMoves[5, 0] = 1;
            explorerValidDiagMoves[5, 1]= -1;
            explorerValidDiagMoves[5, 2] = 9;
            explorerValidDiagMoves[5, 3] = 11;
            explorerValidDiagMoves[6, 0] = -1;
            explorerValidDiagMoves[6, 1] = 2;
            explorerValidDiagMoves[6, 2] = -1;
            explorerValidDiagMoves[6, 3] = 13;
            explorerValidDiagMoves[7, 0] = -1;
            explorerValidDiagMoves[7, 1] = 3;
            explorerValidDiagMoves[7, 2] = 12;
            explorerValidDiagMoves[7, 3] = 14;
            explorerValidDiagMoves[8, 0] = 2;
            explorerValidDiagMoves[8, 1] = 4;
            explorerValidDiagMoves[8, 2] = 13;
            explorerValidDiagMoves[8, 3] = 15;
            explorerValidDiagMoves[9, 0] = 3;
            explorerValidDiagMoves[9, 1] = 5;
            explorerValidDiagMoves[9, 2] = 14;
            explorerValidDiagMoves[9, 3] = 16;
            explorerValidDiagMoves[10, 0] = 4;
            explorerValidDiagMoves[10, 1] = -1;
            explorerValidDiagMoves[10, 2] = 15;
            explorerValidDiagMoves[10, 3] = 17;
            explorerValidDiagMoves[11, 0] = 5;
            explorerValidDiagMoves[11, 1] = -1;
            explorerValidDiagMoves[11, 2] = 16;
            explorerValidDiagMoves[11, 3] = -1;
            explorerValidDiagMoves[12, 0] = -1;
            explorerValidDiagMoves[12, 1] = 7;
            explorerValidDiagMoves[12, 2] = -1;
            explorerValidDiagMoves[12, 3] = 18;
            explorerValidDiagMoves[13, 0] = 6;
            explorerValidDiagMoves[13, 1] = 8;
            explorerValidDiagMoves[13, 2] = -1;
            explorerValidDiagMoves[13, 3] = 19;
            explorerValidDiagMoves[14, 0] = 7;
            explorerValidDiagMoves[14, 1] = 9;
            explorerValidDiagMoves[14, 2] = 18;
            explorerValidDiagMoves[14, 3] = 20;
            explorerValidDiagMoves[15, 0] = 8;
            explorerValidDiagMoves[15, 1] = 10;
            explorerValidDiagMoves[15, 2] = 19;
            explorerValidDiagMoves[15, 3] = 21;
            explorerValidDiagMoves[16, 0] = 9;
            explorerValidDiagMoves[16, 1] = 11;
            explorerValidDiagMoves[16, 2] = 20;
            explorerValidDiagMoves[16, 3] = -1;
            explorerValidDiagMoves[17, 0] = 10;
            explorerValidDiagMoves[17, 1] = -1;
            explorerValidDiagMoves[17, 2] = 21;
            explorerValidDiagMoves[17, 3] = -1;
            explorerValidDiagMoves[18, 0] = 12;
            explorerValidDiagMoves[18, 1] = 14;
            explorerValidDiagMoves[18, 2] = -1;
            explorerValidDiagMoves[18, 3] = 22;
            explorerValidDiagMoves[19, 0] = 13;
            explorerValidDiagMoves[19, 1] = 15;
            explorerValidDiagMoves[19, 2] = -1;
            explorerValidDiagMoves[19, 3] = 23;
            explorerValidDiagMoves[20, 0] = 14;
            explorerValidDiagMoves[20, 1] = 16;
            explorerValidDiagMoves[20, 2] = 22;
            explorerValidDiagMoves[20, 3] = -1;
            explorerValidDiagMoves[21, 0] = 15;
            explorerValidDiagMoves[21, 1] = 17;
            explorerValidDiagMoves[21, 2] = 23;
            explorerValidDiagMoves[21, 3] = -1;
            explorerValidDiagMoves[22, 0] = 18;
            explorerValidDiagMoves[22, 1] = 20;
            explorerValidDiagMoves[22, 2] = -1;
            explorerValidDiagMoves[22, 3] = -1;
            explorerValidDiagMoves[23, 0] = 19;
            explorerValidDiagMoves[23, 1] = 21;
            explorerValidDiagMoves[23, 2] = -1;
            explorerValidDiagMoves[23, 3] = -1;
        }
    }
}
